package ModelLayer;

import java.util.ArrayList;

public class KundeContainer {
	/**
	 * KundeContainer
	 * */
	private ArrayList<Kunde> kundeList;
	
	/**
	 * Singleton attribute
	 * */
	private static KundeContainer instance;
	
	private KundeContainer()
	{
		kundeList = new ArrayList<Kunde>();
	}
	/**
	 * Singleton method*/
	public static KundeContainer getInstance(){
		if(instance == null){
			instance = new KundeContainer();
		}
		return instance;
	}
	/**
	 * Create and 
	 * addKunde to kundeList.
	 * @param String navn, String konto, String adresse, String tlf, int kunderabat, String email.
	 * */
	public void createKunde(String n, String acc, String a, String tlf, int kr, String mail){
		Kunde k = new Kunde(n, acc, a, tlf, kr, mail);
		kundeList.add(k);
	}
	/**
	 * find Kunde and return a Kunde Object.
	 * @param String tlf
	 * */
	public Kunde findKunde(String tlf){
		boolean search = false;
		int index = 0;
		Kunde k = null;
		while(!search && index < kundeList.size()){
			k = kundeList.get(index);
			if(k.getTlf().equals(tlf)){
				search = true;
			}else{
				index++;
			}
		}
		if(search){
			return k;
		}else{
			return null;
		}
	}
	/**
	 * Remove Kunde from kundeList.
	 * Find the Kunde first and then remove.
	 * @param String tlf
	 * */
	public void removeKunde(String tlf){
		boolean search = false;
		int index = 0;
		Kunde k = null;
		while(!search && index < kundeList.size()){
			k = kundeList.get(index);
			if(k.getTlf().equals(tlf)){
				search = true;
			}else{
				index++;
			}
		}
		if(search){
			kundeList.remove(index);
		}
	}//Remove method end
	/**
	 * Find Kunde and update its content.
	 * @param 
	 * */
}
